#!/usr/bin/env python

import string,cgi,time
from os import curdir, sep
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from threading import Thread

class ConsciusWeb(BaseHTTPRequestHandler):
    def do_GET(self):
        try:
			self.send_response(200)
			self.send_header('Content-type', 'text/html')
			self.end_headers()
			self.wfile.write("<html><head><title>ConsciusD Webservice</title></head><body>")
			self.wfile.write("<h1>Found devices:</h1>")
			self.wfile.write("</body>")
			self.wfile.write("</html>")
			return

        except IOError:
			self.send_error(404, "Something went wrong")

        except:
            pass


class WebThread(Thread):
	def run(self, webhost='', webport=8911):		
		try:
			consciusweb = HTTPServer((webhost, int(webport)), ConsciusWeb)
			print "Starting webserver"
			consciusweb.serve_forever()
		
		except KeyboardInterrupt:
			consciusweb.close()